home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 001-025 / disk_002 / cc / zapstring.c < prev   
C/C++ Source or Header  |  1992-05-06  |  1KB  |  63 lines

  1. /*
  2.  *    This is a quick hack to zap strings in an executable file
  3.  *    by replacing their first byte with a null character.  In most
  4.  *    cases, this will effectively turn them into null strings.
  5.  *    This is useful to prevent venders from bombarding you with
  6.  *    irritating startup messages everytime you run their program.
  7.  *    Grrr....
  8.  *
  9.  */
  10.  
  11. #include <stdio.h>
  12.  
  13. main (argc, argv)
  14. int argc;
  15. char *argv[];
  16. {
  17.     FILE *fin = NULL;
  18.     register int ch;
  19.     register char *sp;
  20.     long resync;
  21.     
  22.     if (argc != 3) {
  23.     Fatal (fin, "usage: zapstring <string> <file>");
  24.     }
  25.     fin = fopen (argv[2], "r+");
  26.     sp = argv[1];
  27.     if (fin == NULL) {
  28.     Fatal (fin, "zapstring: can't open file");
  29.     }
  30.     while ((ch = fgetc (fin)) != EOF) {
  31.     if (ch == *sp) {
  32.         resync = ftell (fin);
  33.         while ((ch = fgetc (fin)) != EOF && ch == *++sp && *sp != '\000');
  34.         if (ch != EOF && *sp == '\000') {
  35.         if (fseek (fin, resync - 1, 0) != 0) {
  36.             Fatal (fin, "zapstring: can't resync!");
  37.         }
  38.         if (fputc ('\000', fin) != '\000') {
  39.             Fatal (fin, "zapstring: patch failed in fputc()!");
  40.         }
  41.         break;
  42.         } else {
  43.         sp = argv[1];
  44.         if (fseek (fin, resync, 0) != 0) {
  45.             Fatal (fin, "zapstring: can't resync!");
  46.         }
  47.         }
  48.     }
  49.     }
  50.     fclose (fin);
  51.     exit (0);
  52. }
  53.  
  54.     
  55. Fatal (fin, why)
  56. FILE *fin;
  57. char *why;
  58. {
  59.     fprintf (stderr, "%s\n", why);
  60.     fclose (fin);
  61.     exit (1);
  62. }
  63.